package br.com.android.financas.activities;

import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import br.com.android.financas.R;
import br.com.android.financas.TaxaCallback;
import br.com.android.financas.WebServicePoupanca;

public class ConfiguracaoPoupanca extends PreferenceActivity implements TaxaCallback {
	private Preference bcc,taxa;

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settings);
        final ConfiguracaoPoupanca context=this;
        taxa = findPreference("taxaJuros");
        bcc = findPreference("bcc");

        bcc
		.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

			@Override
			public boolean onPreferenceChange(Preference preference,
					Object newValue) {

				if(((Boolean) newValue)){

					WebServicePoupanca web=new WebServicePoupanca(context,true);
					taxa.setEnabled(false);
				}else{
					taxa.setEnabled(true);
				}


				return true;
			}
		});

    }
	@Override
	public void updateTaxa(float tx){
		taxa.getEditor().putString("taxaJuros", Float.toString(tx)).apply();
	}
}
